package com.ig.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ResourceBundle;

public class DBManager {

	private static String DB_DRIVER = "driver";
	private static String DB_URL = "url";
	private static String DB_USER = "user";
	private static String DB_PASSWORD = "password";
	private static String DB2_DRIVER = "db2_driver";
	private static String DB2_URL = "db2_url";
	private static String DB2_USER = "db2_user";
	private static String DB2_PASSWORD = "db2_password";
	private static String DB_PROPERTIES_FILE = "local-configs";

	public static Connection getMySQLConnection()
			throws ClassNotFoundException, SQLException {
		ResourceBundle rb = ResourceBundle.getBundle(DB_PROPERTIES_FILE);
		// Register the JDBC driver for MySQL.

		Class.forName(rb.getString(DB_DRIVER));

		// Define URL of database server for database named mysql on the
		// localhost with the default port number 3306.
		String url = rb.getString(DB_URL);

		// Get a connection to the database for a user named root with a blank
		// password. This user is the default administrator having full
		// privileges to do anything.
		Connection con = DriverManager.getConnection(url,
				rb.getString(DB_USER), rb.getString(DB_PASSWORD));
		return con;
	}

	public static Connection getDB2Connection() throws ClassNotFoundException,
			SQLException {
		ResourceBundle rb = ResourceBundle.getBundle(DB_PROPERTIES_FILE);
		// Register the JDBC driver for MySQL.

		Class.forName(rb.getString(DB2_DRIVER));

		// Define URL of database server for database named mysql on the
		// localhost with the default port number 3306.
		String url = rb.getString(DB2_URL);

		// Get a connection to the database for a user named root with a blank
		// password. This user is the default administrator having full
		// privileges to do anything.
		Connection con = DriverManager.getConnection(url,
				rb.getString(DB2_USER), rb.getString(DB2_PASSWORD));
		return con;
	}

}
